package com.knowledge.business.controller;


import java.util.Arrays;
import java.util.List;
import java.io.IOException;

import com.knowledge.common.annotation.Log;
import com.knowledge.common.core.controller.BaseController;
import com.knowledge.common.core.domain.AjaxResult;
import com.knowledge.common.enums.BusinessType;
import com.knowledge.common.utils.poi.ExcelUtil;
import jakarta.servlet.http.HttpServletResponse;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.knowledge.business.domain.TProduct;
import com.knowledge.business.service.ITProductService;
import com.knowledge.common.core.page.TableDataInfo;

/**
 * 产品信息Controller
 *
 * @author zhaoyk
 * @date 2025-09-15
 */
@RestController
@RequestMapping("/business/product")
public class TProductController extends BaseController {
    @Autowired
    private ITProductService tProductService;

    /**
     * 查询产品信息列表
     */
//@RequiresPermissions("business:product:list")
    @GetMapping("/list")
    public TableDataInfo list(TProduct tProduct) {
        startPage();
        List<TProduct> list = tProductService.selectTProductList(tProduct);
        return getDataTable(list);
    }

    /**
     * 导出产品信息列表
     */
    //@RequiresPermissions("business:product:export")
    @Log(title = "产品信息", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, TProduct tProduct) {
        List<TProduct> list = tProductService.selectTProductList(tProduct);
        ExcelUtil<TProduct> util = new ExcelUtil<TProduct>(TProduct.class);
        util.exportExcel(response, list, "产品信息数据");
    }

    /**
     * 获取产品信息详细信息
     */
    //@RequiresPermissions("business:product:query")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") String id) {
        return AjaxResult.success(tProductService.getById(id));
    }

    /**
     * 新增产品信息
     */
    //@RequiresPermissions("business:product:add")
    @Log(title = "产品信息", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody TProduct tProduct) {
        return toAjax(tProductService.save(tProduct));
    }

    /**
     * 修改产品信息
     */
    //@RequiresPermissions("business:product:edit")
    @Log(title = "产品信息", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody TProduct tProduct) {
        return toAjax(tProductService.updateById(tProduct));
    }

    /**
     * 删除产品信息
     */
    //@RequiresPermissions("business:product:remove")
    @Log(title = "产品信息", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable String[] ids) {
        return toAjax(tProductService.removeByIds(Arrays.asList(ids)));
    }
}
